const path = require('path')
const Router = require('koa-router')
const { getAllDir } = require('../utils/utils')

const router = new Router({
  // prefix: '/koa' // 路由通用前缀
  prefix: '' // 路由通用前缀
})

/* 遍历所有js文件获取路由 */
let routeDirs = getAllDir(path.join(__dirname, '../routes'), true, /index.js$/)

module.exports = app => {
  routeDirs.forEach(dir => {
    require(dir)(router)
  }) // 路由引入
  /* 启动路由 */
  app.use(router.routes());
  app.use(router.allowedMethods());
}
